{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-02-12T08:57:04.581060Z",
     "start_time": "2025-02-12T08:57:04.578409Z"
    }
   },
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt"
   ],
   "outputs": [],
   "execution_count": 36
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-12T08:57:04.722753Z",
     "start_time": "2025-02-12T08:57:04.582500Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#商品数据\n",
    "train=pd.read_csv('tianchi_fresh_comp_train_item.csv')\n",
    "train"
   ],
   "id": "206249c6567430c9",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "          item_id item_geohash  item_category\n",
       "0       100002303          NaN           3368\n",
       "1       100003592          NaN           7995\n",
       "2       100006838          NaN          12630\n",
       "3       100008089          NaN           7791\n",
       "4       100012750          NaN           9614\n",
       "...           ...          ...            ...\n",
       "620913   99994679          NaN           9205\n",
       "620914   99995241          NaN            597\n",
       "620915   99998434          NaN           8099\n",
       "620916   99998861          NaN          12553\n",
       "620917   99999855          NaN           3900\n",
       "\n",
       "[620918 rows x 3 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>item_id</th>\n",
       "      <th>item_geohash</th>\n",
       "      <th>item_category</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100002303</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3368</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100003592</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100006838</td>\n",
       "      <td>NaN</td>\n",
       "      <td>12630</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100008089</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7791</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>100012750</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9614</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>620913</th>\n",
       "      <td>99994679</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9205</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>620914</th>\n",
       "      <td>99995241</td>\n",
       "      <td>NaN</td>\n",
       "      <td>597</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>620915</th>\n",
       "      <td>99998434</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8099</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>620916</th>\n",
       "      <td>99998861</td>\n",
       "      <td>NaN</td>\n",
       "      <td>12553</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>620917</th>\n",
       "      <td>99999855</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3900</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>620918 rows × 3 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 37
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-12T08:57:04.741336Z",
     "start_time": "2025-02-12T08:57:04.723759Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#检查空值\n",
    "train.isnull().sum()"
   ],
   "id": "240173aded5a530f",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "item_id               0\n",
       "item_geohash     417508\n",
       "item_category         0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 38
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-12T08:57:04.832050Z",
     "start_time": "2025-02-12T08:57:04.742344Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#检查是否有重复行\n",
    "train.duplicated().sum()"
   ],
   "id": "ad7402ba94c8a78d",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 39
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-12T08:57:14.154995Z",
     "start_time": "2025-02-12T08:57:04.833066Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 用户行为数据\n",
    "user=pd.read_csv('tianchi_fresh_comp_train_user.csv')\n",
    "user"
   ],
   "id": "418a1c1b1104f10b",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "           user_id    item_id  behavior_type user_geohash  item_category  \\\n",
       "0         10001082  285259775              1      97lk14c           4076   \n",
       "1         10001082    4368907              1          NaN           5503   \n",
       "2         10001082    4368907              1          NaN           5503   \n",
       "3         10001082   53616768              1          NaN           9762   \n",
       "4         10001082  151466952              1          NaN           5232   \n",
       "...            ...        ...            ...          ...            ...   \n",
       "23291022  65341491  259008790              1          NaN          13164   \n",
       "23291023  65341491  336404938              1          NaN          13164   \n",
       "23291024  65341491   52142024              1      95qhbsu           5201   \n",
       "23291025  65341491  250557965              1          NaN          13164   \n",
       "23291026  65341491  300315408              1          NaN           1838   \n",
       "\n",
       "                   time  \n",
       "0         2014-12-08 18  \n",
       "1         2014-12-12 12  \n",
       "2         2014-12-12 12  \n",
       "3         2014-12-02 15  \n",
       "4         2014-12-12 11  \n",
       "...                 ...  \n",
       "23291022  2014-12-03 12  \n",
       "23291023  2014-12-03 12  \n",
       "23291024  2014-12-10 22  \n",
       "23291025  2014-12-03 12  \n",
       "23291026  2014-11-29 08  \n",
       "\n",
       "[23291027 rows x 6 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>item_id</th>\n",
       "      <th>behavior_type</th>\n",
       "      <th>user_geohash</th>\n",
       "      <th>item_category</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10001082</td>\n",
       "      <td>285259775</td>\n",
       "      <td>1</td>\n",
       "      <td>97lk14c</td>\n",
       "      <td>4076</td>\n",
       "      <td>2014-12-08 18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10001082</td>\n",
       "      <td>4368907</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5503</td>\n",
       "      <td>2014-12-12 12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10001082</td>\n",
       "      <td>4368907</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5503</td>\n",
       "      <td>2014-12-12 12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10001082</td>\n",
       "      <td>53616768</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9762</td>\n",
       "      <td>2014-12-02 15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10001082</td>\n",
       "      <td>151466952</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5232</td>\n",
       "      <td>2014-12-12 11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23291022</th>\n",
       "      <td>65341491</td>\n",
       "      <td>259008790</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>13164</td>\n",
       "      <td>2014-12-03 12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23291023</th>\n",
       "      <td>65341491</td>\n",
       "      <td>336404938</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>13164</td>\n",
       "      <td>2014-12-03 12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23291024</th>\n",
       "      <td>65341491</td>\n",
       "      <td>52142024</td>\n",
       "      <td>1</td>\n",
       "      <td>95qhbsu</td>\n",
       "      <td>5201</td>\n",
       "      <td>2014-12-10 22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23291025</th>\n",
       "      <td>65341491</td>\n",
       "      <td>250557965</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>13164</td>\n",
       "      <td>2014-12-03 12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23291026</th>\n",
       "      <td>65341491</td>\n",
       "      <td>300315408</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1838</td>\n",
       "      <td>2014-11-29 08</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>23291027 rows × 6 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 40
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-12T08:57:15.378156Z",
     "start_time": "2025-02-12T08:57:14.156010Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#检查空值\n",
    "user.isnull().sum()"
   ],
   "id": "da21a19ea60d6ad9",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_id                 0\n",
       "item_id                 0\n",
       "behavior_type           0\n",
       "user_geohash     15911010\n",
       "item_category           0\n",
       "time                    0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 41
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-12T08:57:24.383427Z",
     "start_time": "2025-02-12T08:57:15.379161Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#检查是否有重复行\n",
    "user.duplicated().sum()"
   ],
   "id": "5a10caf4f2c8d24b",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7827917"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 42
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-12T08:57:35.237324Z",
     "start_time": "2025-02-12T08:57:24.383427Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#查看每个item_id有多少重复\n",
    "user.value_counts().head()"
   ],
   "id": "43b322db1c4fcd29",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_id    item_id    behavior_type  user_geohash  item_category  time         \n",
       "24758644   155836094  1              94nutdc       4830           2014-12-11 21    5\n",
       "103246987  187593746  1              95rwgjo       1797           2014-12-12 20    4\n",
       "27169453   39512240   1              95qcstc       10392          2014-11-21 16    4\n",
       "124435826  19308573   1              990cqen       6648           2014-11-29 11    4\n",
       "27559334   19097257   1              96updik       437            2014-12-02 08    4\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 43
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-12T08:57:44.657145Z",
     "start_time": "2025-02-12T08:57:35.238508Z"
    }
   },
   "cell_type": "code",
   "source": [
    "users = user.drop_duplicates()\n",
    "users"
   ],
   "id": "35407cbd0d7370a0",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "           user_id    item_id  behavior_type user_geohash  item_category  \\\n",
       "0         10001082  285259775              1      97lk14c           4076   \n",
       "1         10001082    4368907              1          NaN           5503   \n",
       "3         10001082   53616768              1          NaN           9762   \n",
       "4         10001082  151466952              1          NaN           5232   \n",
       "5         10001082   53616768              4          NaN           9762   \n",
       "...            ...        ...            ...          ...            ...   \n",
       "23291015  65341491  155217475              2          NaN           3093   \n",
       "23291018  65341491  154674105              1      95qhbpe          12510   \n",
       "23291019  65341491   42748021              1      95qhb0r          12510   \n",
       "23291023  65341491  336404938              1          NaN          13164   \n",
       "23291024  65341491   52142024              1      95qhbsu           5201   \n",
       "\n",
       "                   time  \n",
       "0         2014-12-08 18  \n",
       "1         2014-12-12 12  \n",
       "3         2014-12-02 15  \n",
       "4         2014-12-12 11  \n",
       "5         2014-12-02 15  \n",
       "...                 ...  \n",
       "23291015  2014-12-18 01  \n",
       "23291018  2014-12-08 12  \n",
       "23291019  2014-12-08 12  \n",
       "23291023  2014-12-03 12  \n",
       "23291024  2014-12-10 22  \n",
       "\n",
       "[15463110 rows x 6 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>item_id</th>\n",
       "      <th>behavior_type</th>\n",
       "      <th>user_geohash</th>\n",
       "      <th>item_category</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10001082</td>\n",
       "      <td>285259775</td>\n",
       "      <td>1</td>\n",
       "      <td>97lk14c</td>\n",
       "      <td>4076</td>\n",
       "      <td>2014-12-08 18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10001082</td>\n",
       "      <td>4368907</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5503</td>\n",
       "      <td>2014-12-12 12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10001082</td>\n",
       "      <td>53616768</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9762</td>\n",
       "      <td>2014-12-02 15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10001082</td>\n",
       "      <td>151466952</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5232</td>\n",
       "      <td>2014-12-12 11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>10001082</td>\n",
       "      <td>53616768</td>\n",
       "      <td>4</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9762</td>\n",
       "      <td>2014-12-02 15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23291015</th>\n",
       "      <td>65341491</td>\n",
       "      <td>155217475</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3093</td>\n",
       "      <td>2014-12-18 01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23291018</th>\n",
       "      <td>65341491</td>\n",
       "      <td>154674105</td>\n",
       "      <td>1</td>\n",
       "      <td>95qhbpe</td>\n",
       "      <td>12510</td>\n",
       "      <td>2014-12-08 12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23291019</th>\n",
       "      <td>65341491</td>\n",
       "      <td>42748021</td>\n",
       "      <td>1</td>\n",
       "      <td>95qhb0r</td>\n",
       "      <td>12510</td>\n",
       "      <td>2014-12-08 12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23291023</th>\n",
       "      <td>65341491</td>\n",
       "      <td>336404938</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>13164</td>\n",
       "      <td>2014-12-03 12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23291024</th>\n",
       "      <td>65341491</td>\n",
       "      <td>52142024</td>\n",
       "      <td>1</td>\n",
       "      <td>95qhbsu</td>\n",
       "      <td>5201</td>\n",
       "      <td>2014-12-10 22</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>15463110 rows × 6 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 44
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-12T10:13:09.858631Z",
     "start_time": "2025-02-12T10:13:08.051561Z"
    }
   },
   "cell_type": "code",
   "source": [
    "userSub = pd.merge(users,train,on = 'item_id',how = 'inner')\n",
    "userSub"
   ],
   "id": "b9f646bb604e9003",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "          user_id    item_id  behavior_type user_geohash  item_category_x  \\\n",
       "0        10001082  275221686              1          NaN            10576   \n",
       "1        10001082   97441652              1          NaN            10576   \n",
       "2        10001082  275221686              1          NaN            10576   \n",
       "3        10001082  275221686              1          NaN            10576   \n",
       "4        10001082  125083630              1          NaN             4722   \n",
       "...           ...        ...            ...          ...              ...   \n",
       "2769024  65341491  264469913              1      95qhbs0             3942   \n",
       "2769025  65341491  191375871              1      95qhbsq             3942   \n",
       "2769026  65341491  133486908              1      95qhbs3             3942   \n",
       "2769027  65341491  242501625              1      95qhbs7             3942   \n",
       "2769028  65341491  133486908              1      95qhb09             3942   \n",
       "\n",
       "                  time item_geohash  item_category_y  \n",
       "0        2014-12-03 01          NaN            10576  \n",
       "1        2014-11-20 21          NaN            10576  \n",
       "2        2014-12-13 14          NaN            10576  \n",
       "3        2014-12-08 07          NaN            10576  \n",
       "4        2014-12-14 03          NaN             4722  \n",
       "...                ...          ...              ...  \n",
       "2769024  2014-12-08 19          NaN             3942  \n",
       "2769025  2014-12-08 19          NaN             3942  \n",
       "2769026  2014-12-08 19          NaN             3942  \n",
       "2769027  2014-12-08 19          NaN             3942  \n",
       "2769028  2014-12-08 19          NaN             3942  \n",
       "\n",
       "[2769029 rows x 8 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>item_id</th>\n",
       "      <th>behavior_type</th>\n",
       "      <th>user_geohash</th>\n",
       "      <th>item_category_x</th>\n",
       "      <th>time</th>\n",
       "      <th>item_geohash</th>\n",
       "      <th>item_category_y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10001082</td>\n",
       "      <td>275221686</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10576</td>\n",
       "      <td>2014-12-03 01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10576</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10001082</td>\n",
       "      <td>97441652</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10576</td>\n",
       "      <td>2014-11-20 21</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10576</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10001082</td>\n",
       "      <td>275221686</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10576</td>\n",
       "      <td>2014-12-13 14</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10576</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10001082</td>\n",
       "      <td>275221686</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10576</td>\n",
       "      <td>2014-12-08 07</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10576</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10001082</td>\n",
       "      <td>125083630</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4722</td>\n",
       "      <td>2014-12-14 03</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4722</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2769024</th>\n",
       "      <td>65341491</td>\n",
       "      <td>264469913</td>\n",
       "      <td>1</td>\n",
       "      <td>95qhbs0</td>\n",
       "      <td>3942</td>\n",
       "      <td>2014-12-08 19</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3942</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2769025</th>\n",
       "      <td>65341491</td>\n",
       "      <td>191375871</td>\n",
       "      <td>1</td>\n",
       "      <td>95qhbsq</td>\n",
       "      <td>3942</td>\n",
       "      <td>2014-12-08 19</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3942</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2769026</th>\n",
       "      <td>65341491</td>\n",
       "      <td>133486908</td>\n",
       "      <td>1</td>\n",
       "      <td>95qhbs3</td>\n",
       "      <td>3942</td>\n",
       "      <td>2014-12-08 19</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3942</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2769027</th>\n",
       "      <td>65341491</td>\n",
       "      <td>242501625</td>\n",
       "      <td>1</td>\n",
       "      <td>95qhbs7</td>\n",
       "      <td>3942</td>\n",
       "      <td>2014-12-08 19</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3942</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2769028</th>\n",
       "      <td>65341491</td>\n",
       "      <td>133486908</td>\n",
       "      <td>1</td>\n",
       "      <td>95qhb09</td>\n",
       "      <td>3942</td>\n",
       "      <td>2014-12-08 19</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3942</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2769029 rows × 8 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 49
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-12T10:17:43.344144Z",
     "start_time": "2025-02-12T10:17:43.339964Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#因为空值占数据的一半多所以选择删除\n",
    "del [userSub['user_geohash']]\n",
    "del [userSub['item_geohash']]"
   ],
   "id": "c09a7ca83c811624",
   "outputs": [],
   "execution_count": 53
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-12T10:17:52.047029Z",
     "start_time": "2025-02-12T10:17:52.041299Z"
    }
   },
   "cell_type": "code",
   "source": "userSub",
   "id": "d39c924c7ff1152f",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "          user_id    item_id  behavior_type           time\n",
       "0        10001082  275221686              1  2014-12-03 01\n",
       "1        10001082   97441652              1  2014-11-20 21\n",
       "2        10001082  275221686              1  2014-12-13 14\n",
       "3        10001082  275221686              1  2014-12-08 07\n",
       "4        10001082  125083630              1  2014-12-14 03\n",
       "...           ...        ...            ...            ...\n",
       "2769024  65341491  264469913              1  2014-12-08 19\n",
       "2769025  65341491  191375871              1  2014-12-08 19\n",
       "2769026  65341491  133486908              1  2014-12-08 19\n",
       "2769027  65341491  242501625              1  2014-12-08 19\n",
       "2769028  65341491  133486908              1  2014-12-08 19\n",
       "\n",
       "[2769029 rows x 4 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>item_id</th>\n",
       "      <th>behavior_type</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10001082</td>\n",
       "      <td>275221686</td>\n",
       "      <td>1</td>\n",
       "      <td>2014-12-03 01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10001082</td>\n",
       "      <td>97441652</td>\n",
       "      <td>1</td>\n",
       "      <td>2014-11-20 21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10001082</td>\n",
       "      <td>275221686</td>\n",
       "      <td>1</td>\n",
       "      <td>2014-12-13 14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10001082</td>\n",
       "      <td>275221686</td>\n",
       "      <td>1</td>\n",
       "      <td>2014-12-08 07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10001082</td>\n",
       "      <td>125083630</td>\n",
       "      <td>1</td>\n",
       "      <td>2014-12-14 03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2769024</th>\n",
       "      <td>65341491</td>\n",
       "      <td>264469913</td>\n",
       "      <td>1</td>\n",
       "      <td>2014-12-08 19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2769025</th>\n",
       "      <td>65341491</td>\n",
       "      <td>191375871</td>\n",
       "      <td>1</td>\n",
       "      <td>2014-12-08 19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2769026</th>\n",
       "      <td>65341491</td>\n",
       "      <td>133486908</td>\n",
       "      <td>1</td>\n",
       "      <td>2014-12-08 19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2769027</th>\n",
       "      <td>65341491</td>\n",
       "      <td>242501625</td>\n",
       "      <td>1</td>\n",
       "      <td>2014-12-08 19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2769028</th>\n",
       "      <td>65341491</td>\n",
       "      <td>133486908</td>\n",
       "      <td>1</td>\n",
       "      <td>2014-12-08 19</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2769029 rows × 4 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 54
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-12T10:20:15.789196Z",
     "start_time": "2025-02-12T10:20:12.782663Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#处理数据 然后存入到userSub中\n",
    "userSub.to_csv('userSub.csv')"
   ],
   "id": "53d0e88b3eed0315",
   "outputs": [],
   "execution_count": 55
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
